package com.hrhr74.penguinstream.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.hrhr74.penguinstream.constant.UserConstant;
import com.hrhr74.penguinstream.domain.dto.UserEditDTO;
import com.hrhr74.penguinstream.domain.po.User;
import com.hrhr74.penguinstream.service.UserEdit;
import com.hrhr74.penguinstream.utils.Result;
import org.springframework.stereotype.Service;

@Service(UserConstant.ADMIN)
public class UserEditAdmin extends UserEdit {

    @Override
    public Result editUser(UserEditDTO userEditDTO) {
        if(userEditDTO == null){
            return Result.error("该用户信息修改失败！");
        }

        User user = Db.lambdaQuery(User.class).eq(User::getId,userEditDTO.getId()).one();


        if(user == null){
            return Result.error("该用户信息修改失败！");
        }

        User newUser = BeanUtil.copyProperties(userEditDTO,User.class);

        boolean update = Db.updateById(newUser);

        return update ? Result.ok("该用户信息修改成功！"): Result.error("该用户信息修改失败！");
    }
}
